package com.csu.tingtian.controller;

import com.csu.tingtian.common.CommonResponse;
import com.csu.tingtian.service.RentOrderService;
import com.csu.tingtian.vo.RentOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rentorder/")
public class RentOrderController {
    @Autowired
    private RentOrderService rentOrderService;

    //获取所有租赁订单信息
    @GetMapping("rentorders")
    public CommonResponse<List<RentOrder>> getAllRentOrder(){
        return rentOrderService.getAllRentOrder();
    }
    //根据用户姓名查询租赁订单
    @GetMapping("{rentusername}/rentorders")
    CommonResponse<List<RentOrder>> getRentOrderByRentUserName(@PathVariable("rentusername") String rentUserName){
        return rentOrderService.getRentOrderByRentUserName(rentUserName);
    }

    //根据用户Id查询租赁订单
    @GetMapping("{rentorderid}")
    CommonResponse<RentOrder> getRentOrderByRentOrderId(@PathVariable("rentorderid") int rentOrderId){
        return rentOrderService.getRentOrderByRentOrderId(rentOrderId);
    }

    //插入一条租赁订单
    @PostMapping("rentorders/rentorder")
    CommonResponse<RentOrder> insertRentOrder(@RequestBody RentOrder rentOrder){
        return rentOrderService.insertRentOrder(rentOrder);
    }

    //删除一条租赁订单
    @DeleteMapping("{rentorderid}")
    CommonResponse<RentOrder> deleteRentOrderByRentOrderId(@PathVariable("rentorderid") int rentOrderId){
        return rentOrderService.deleteRentOrderByRentOrderId(rentOrderId);
    }

    //更改一条租赁订单信息
    @PutMapping("rentorders/rentorder")
    CommonResponse<RentOrder> updateRentOrder(@RequestBody RentOrder rentOrder){
        return rentOrderService.updateRentOrder(rentOrder);
    }

}
